<?php
/*
 * @Author: your name
 * @Date: 2020-12-24 16:22:44
 * @LastEditTime: 2020-12-28 10:05:49
 * @LastEditors: Please set LastEditors
 * @Description: 允许ip逻辑层
 * @FilePath: /special/application/common/service/platform_manage/ServerAllowIpService.php
 */

namespace app\common\service\platform_manage;


use think\Db;

class ServerAllowIpService
{
    /**
     * @name 查询
     * @param $condition
     * @return array|null|\PDOStatement|string|\think\Model
     * @author wx
     * @date 2019/10/21 16:45
     */
    public function findData($condition)
    {
        return Db::name('server_allow_ip')->where($condition)->find();
    }

    /**
     * @name 添加
     * @param $data
     * @return int|string
     * @author wx
     * @date 2019/10/22 17:35
     */
    public function add($data)
    {
        return Db::name('server_allow_ip')->insert($data);
    }

    public function list($params)
    {
        //查询
        $db = Db::name('server_allow_ip');

        //条件筛选
        if(isset($params['ip']) && !empty($params['ip'])){
            $db->where('ip','like','%'.$params['ip'].'%');
        }
        if (isset($params['login_time']) && !empty($params['login_time'])) {
            $startTime = strtotime($params['login_time']);
            $endTime = $startTime + 86399;
            $db->where('login_time','between',[$startTime, $endTime]);
        }

        //查询数据
        $data = $db->order('login_time desc')
            ->field('id,ip,login_time')->paginate()->toArray();

        return $data;
    }

    public function modify($condition, $updateData)
    {
        return Db::name('server_allow_ip')->where($condition)->update($updateData);
    }

    /**
     * @name 删除
     * @param $condition
     * @return int
     * @author wx
     * @date 2019/10/28 10:52
     */
    public function del($condition)
    {
        return Db::name('server_allow_ip')->where($condition)->delete();
    }
}